//
//  ZZXLocationPageCollectionViewCell.m
//  Travel
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 doll. All rights reserved.
//

#import "ZZXLocationPageCollectionViewCell.h"
#import "UIImageView+WebCache.h"

@interface ZZXLocationPageCollectionViewCell ()

@property (nonatomic, strong)UIImageView *backImg;
@property (nonatomic, strong)UILabel *labelTilte;
@property (nonatomic, strong)UIImageView *dieViewCountImg;
@property (nonatomic, strong)UILabel *viewCountLabel;
@property (nonatomic, strong)UIImageView *dieLikeImg;
@property (nonatomic, strong)UILabel *likeLable;



@end

@implementation ZZXLocationPageCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView
{
    self.backImg = [[UIImageView alloc]init];
    [self.contentView addSubview:self.backImg];
    self.backImg.contentMode = UIViewContentModeScaleAspectFill;
    self.backImg.clipsToBounds = YES;
  
    
    
    self.labelTilte = [[UILabel alloc]init];
    [self.contentView addSubview:self.labelTilte];
    self.labelTilte.font = [UIFont systemFontOfSize:15];
    self.labelTilte.numberOfLines = 2;

    
    self.dieViewCountImg = [[UIImageView alloc]init];
    [self.contentView addSubview:self.dieViewCountImg];
    self.dieViewCountImg.image = [UIImage imageNamed:@"chakan"];
  
    
    self.viewCountLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.viewCountLabel];
    self.viewCountLabel.font = [UIFont systemFontOfSize:10];
   
    
    self.dieLikeImg = [[UIImageView alloc]init];
    self.dieLikeImg.image = [UIImage imageNamed:@"like"];
    [self.contentView addSubview:self.dieLikeImg];
    
    
    self.likeLable = [[UILabel alloc]init];
    [self.contentView addSubview:self.likeLable];
    self.likeLable.font = [UIFont systemFontOfSize:10];
    
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    
    [super applyLayoutAttributes:layoutAttributes];
    
    //夜间模式
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"isNight"]) {
        self.contentView.backgroundColor = [UIColor colorWithRed:0.28 green:0.28 blue:0.28 alpha:1];
        self.labelTilte.textColor = [UIColor whiteColor];
        self.likeLable.textColor = [UIColor whiteColor];
        self.viewCountLabel.textColor = [UIColor whiteColor];
    }else
    {
        self.contentView.backgroundColor = [UIColor colorWithRed:0.98 green:0.97 blue:0.93 alpha:1];
    }
    
    self.backImg.frame = CGRectMake(0, 0, layoutAttributes.frame.size.width, layoutAttributes.frame.size.height * 0.7);
    self.labelTilte.frame = CGRectMake(10, self.backImg.frame.size.height + 5, layoutAttributes.frame.size.width - 20, 45);
    
    self.dieViewCountImg.frame = CGRectMake(10, self.labelTilte.frame.origin.y + self.labelTilte.frame.size.height + 10, 15, 15);
    self.viewCountLabel.frame = CGRectMake(self.dieViewCountImg.frame.origin.x + self.dieViewCountImg.frame.size.width + 5, self.dieViewCountImg.frame.origin.y, 60, self.dieViewCountImg.frame.size.height);
    
    self.dieLikeImg.frame = CGRectMake(self.viewCountLabel.frame.size.width + self.viewCountLabel.frame.origin.x, self.viewCountLabel.frame.origin.y, 15, 15);
    self.likeLable.frame = CGRectMake(self.dieLikeImg.frame.origin.x + self.dieLikeImg.frame.size.width + 5, self.dieLikeImg.frame.origin.y, layoutAttributes.frame.size.width - self.dieLikeImg.frame.origin.x + self.dieLikeImg.frame.size.width + 5 , self.dieLikeImg.frame.size.height);
    
}

- (void)setGuideModel:(ZZXstrategryModel *)guideModel
{
    self.labelTilte.text = guideModel.title;
    if (guideModel.viewCnt.integerValue / 1000 < 0) {
        self.viewCountLabel.text = guideModel.viewCnt;
    }
    else
    {
        NSInteger i = guideModel.viewCnt.integerValue / 1000;
        NSInteger j = guideModel.viewCnt.integerValue % 1000 / 100;
        self.viewCountLabel.text = [NSString stringWithFormat:@"%ld%@%ld%@",i, @".", j, @"k"];
    }
    
    self.likeLable.text = guideModel.cntFav;
    
    NSString *url = [NSString stringWithFormat:@"%@%@%@", guideModel.picdomain,@"upload/",guideModel.coverpic];
//    [self.backImg sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage sd_animatedGIFNamed:@"load"]];
//    

        [self.backImg sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"load.png"] ];
    
}









@end
